<template>
	<view>
		<view class="cu-bar bg-gradual-green">
			<view class="action">
				<text class="cuIcon-homefill text-white"></text> 首页
			</view>
			<view class="content text-bold">
				入库
			</view>
			<view class="action">
				<text class="cuIcon-scan text-white" v-on:click="showScan"></text>
			</view>
		</view>
		<form>
			<view class="cu-form-group margin-top">
				<view class="title">项目编号:</view>
				<input placeholder="项目编号" name="projectNo" class="text-right" v-model="projectNo" disabled></input>
				<text class='cuIcon-right text-gray'></text>
			</view>
			<view class="cu-form-group">
				<view class="title">分布场所:</view>
				<input placeholder="分布场所" name="projectPlace" class="text-right" v-model="projectPlace" disabled></input>
				<text class='cuIcon-locationfill text-gray'></text>
			</view>
			<view class="cu-form-group">
				<view class="title">库位:</view>
				<input placeholder="库位" name="storeNo" class="text-right" v-model="storeNo" disabled></input>
				<text class='cuIcon-tag text-gray'></text>
			</view>
			<view class="cu-form-group">
				<view class="title">数量:</view>
				<input placeholder="数量" name="number" class="text-right" v-model="number"></input>
				<text class='cuIcon-sort text-gray'></text>
			</view>
			<view style="margin-top: 50rpx;">
				<button class="cu-btn block bg-green margin-tb-sm lg" v-on:click="saveData" :disabled="loading">
					<text class="cuIcon-loading2 cuIconfont-spin" v-show="loading"></text> 提交
				</button>
			</view>
		</form>
		<view class="cu-bar tabbar margin-bottom-xl bg-white foot">
			<view class="action text-green">
				<view class="cuIcon-homefill"></view> 首页
			</view>
			<view class="action text-gray">
				<view class="cuIcon-apps"></view> 项目
			</view>
			<view class="action text-gray add-action">
				<button class="cu-btn cuIcon-add bg-green shadow"></button>
				发布
			</view>
			<view class="action text-gray">
				<view class="cuIcon-calendar">
					<view class="cu-tag badge">99</view>
				</view>
				待办
			</view>
			<view class="action text-gray">
				<view class="cuIcon-my">
					<view class="cu-tag badge"></view>
				</view>
				我的
			</view>
		</view>
	</view>
</template>

<script>
	import * as dd from 'dingtalk-jsapi';
	export default {
		data() {
			return {
				loading: false,
				projectNo: 'N20200919290098',
				projectPlace: 'T001',
				storeNo: 'S-223',
				number: 100
			};
		},
		mounted() {
			
		},
		methods: {
			// 显示扫一扫
			showScan: function() {
				let me = this;
				dd.biz.util.scan({
				    type: 'qrCode',
				    onSuccess: function(data) {
						var dataArr = data.split('*');
						me.projectNo = dataArr[0];
						me.projectPlace = dataArr[1];
						me.storeNo = dataArr[2];
						me.number = dataArr[3];
				    },
				   onFail : function(err) {
					   alert('扫码失败');
				   }
				})
			},
			// 保存
			saveData: function() {
				let me = this;
				me.loading = true;
				
				setTimeout(function() {
					me.loading = false;
					let postData = {
						projectNo: me.projectNo,
						projectPlace: me.projectPlace,
						storeNo: me.storeNo,
						number: me.number
					};
					uni.request({
						url:'http://www.baidu.com',
						method:"POST",
						data: postData,
						dataType:"json",
						success: (res) => {
							if(res.data.status !== 0){
								uni.showToast({
									title:"提交成功"
								})
							}
						},
						fail: (err) => {
							uni.showToast({
								title:"接口请求失败"
							})
						}
					})
				}, 2000);
			}
		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
</style>
